#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
"""
# 1、将names=['egon','alex_sb','wupeiqi','yuanhao']中的名字全部变大写
names=['egon','alex_sb','wupeiqi','yuanhao']
n1= [name.upper() for name in names]
print(n1)

# 2、将 names=['egon','alex_sb','wupeiqi','yuanhao']中以sb结尾的名字过滤掉，然后保存剩下的名字长度
names=['egon','alex_sb','wupeiqi','yuanhao']
n2 = [ name for name in names if not name.endswith("sb")]
print(n2)

# 3、求文件a.txt中最长的行的长度（长度按字符个数算，需要使用max函数）
with open("a.txt", "r", encoding="utf-8") as read_f:
    xx = [len(i) for i in read_f.readlines()]
    print(xx, max(xx))

with open("a.txt", "r", encoding="utf-8") as read_f:
    print(max([len(i) for i in read_f.readlines()]))

# 4、求文件a.txt中总共包含的字符个数？思考为何在第一次之后的n次sum求和得到的结果为0？（需要使用sum函数）
n=0
with open("a.txt", "r", encoding="utf-8") as read_f:
    xx = [len(i) for i in read_f.readlines()]
print(sum(xx))

print(xx)
for i in xx:
    n+=i
print(n)
"""

"""

求shopping.txt总共花了多少钱？
打印出所有商品的信息，格式为[{'name':'xxx','price':333,'count':3},...]
求单价大于10000的商品信息,格式同上
"""
shop = ["name", "price", "count"]
with open("shopping.txt", "r", encoding="utf-8") as read_f:
    li = [i.strip().split(",") for i in read_f]

x = [{k: v for k, v in zip(shop, i)} for i in li]
print(x)

x = max((int(i[1]) for i in li))
y = sum((int(i[1]) for i in li))
print(x,y)
